﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace Org.LyrcsoftFramework.Cloud.Extensions
{
    public static class ConfigureDependencyExtentions
    {
        private const string FEIGN_SERVICES = "^([a-zA-z]*).Feign.Service";

        internal static List<Assembly> assemblyDictionary;

        /// <summary>
        /// 获取规则命名下的Feign服务定义
        /// </summary>
        /// <returns></returns>
        internal static List<Assembly> GetAssemblies()
        {
            if (assemblyDictionary != null && assemblyDictionary.Any())
            {
                return assemblyDictionary;
            }
            assemblyDictionary = AppDomain.CurrentDomain.GetAssemblies().Where((assembly) =>
            {
                return !assembly.IsDynamic && Regex.IsMatch(assembly.FullName, FEIGN_SERVICES);
            }).ToList();
            return assemblyDictionary;
        }
    }
}
